package com.aaa.controller.tables;

import com.aaa.dao.FOrderDao;
import com.aaa.dao.FOrderMapper;
import com.wsc.entity.FOrder;
import com.wsc.entity.FReturns;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("forder")
public class FOrderController {
//    @Resource
//    FOrderService fOrderService;
    @Resource
FOrderMapper fOrderMapper;
//    @Resource
//    FOrderPMapper fOrderPMapper;
    @Resource
FOrderDao fOrderDao;
//    @RequestMapping("select")
//    public List<FOrder> select(Integer pageCode,Integer pageSize,FOrder fOrder){
//        System.out.println(pageCode+","+pageSize);
//        return fOrderService.select(pageCode, pageSize,fOrder);
//    }
//    @RequestMapping("insert")
//    public String insert(FOrder fOrder, FOrderp fOrderp){
//        Integer a= fOrderMapper.insert(fOrder);
//        QueryWrapper<FOrder> fOrderQueryWrapper = new QueryWrapper<>();
//        fOrderQueryWrapper.select("id").eq("parcelid",fOrder.getParcelid());
//        FOrder fOrder1 = fOrderMapper.selectList(fOrderQueryWrapper).get(0);
//        long id= fOrder1.getId();
//        System.out.println(id);
//        fOrderp.setFOrder(id);
//        Integer b= fOrderPMapper.insert(fOrderp);
//        if(a>0&&b>0){
//            return "提交成功";
//        }else{
//            return "提交失败";
//        }
//    }
//    @RequestMapping("insert1")
//    public Integer insert1(FOrder fOrder) {
//        System.out.println(fOrder.getFUser()+"用户");
//        return fOrderMapper.insert(fOrder);
//    }
//    @RequestMapping("delete")
//    public String delete(Integer id){
//        QueryWrapper<FOrderp> fOrderQueryWrapper = new QueryWrapper<>();
//        fOrderQueryWrapper.eq("f_order",id);
//        Integer b=fOrderPMapper.delete(fOrderQueryWrapper);
//        Integer a= fOrderMapper.deleteById(id);
//        if(a>0&&b>0){
//            return "删除成功";
//        }else{
//            return "删除失败";
//        }
//    }
//    @RequestMapping("update")
//    public Boolean insert(FOrder fOrder){
//        return new LambdaUpdateChainWrapper<FOrder>(fOrderMapper)
//                .eq(FOrder::getId,fOrder.getId())
//                .set(FOrder::getState, fOrder.getState())
//                .update()
//                ;
//    }
//
//    @RequestMapping("insert2")
//    public String insert2(FOrder fOrder,Integer book[],Integer num[],Integer price1[]){
//        //System.out.println(book+","+num+","+price1);
//        //http://localhost:8080/forder/insert?id=0&fUser=13&parcelid=21002&book=1,2,3&price1=99,33,33&num=1,1,1&fSite=25&state=4
//        Integer sumPrice=0;
//        for (int i=0;i<price1.length;i++){
//            System.out.println(price1[i]+","+num[i]+","+book[i]);
//            Integer a=price1[i]*num[i];
//            sumPrice+=a;
//        }
//        System.out.println(sumPrice+"这是总金额");
//        fOrder.setPrice(sumPrice);
//        Integer a= fOrderMapper.insert(fOrder);
//        QueryWrapper<FOrder> fOrderQueryWrapper = new QueryWrapper<>();
//        fOrderQueryWrapper.select("id").eq("parcelid",fOrder.getParcelid());
//        FOrder fOrder1 = fOrderMapper.selectList(fOrderQueryWrapper).get(0);
//        long id= fOrder1.getId();
//        System.out.println(id);
//        FOrderp fOrderp=new FOrderp();
//        fOrderp.setFOrder(id);
//        //Integer b= fOrderPMapper.insert(fOrderp);
//        for (int i=0;i<book.length;i++){
//           fOrderp.setBook(book[i]);
//           fOrderp.setNum(num[i]);
//           fOrderp.setPrice(price1[i]);
//           Integer moneys=num[i]*price1[i];
//           fOrderp.setMoney(moneys);
//           fOrderPMapper.insert(fOrderp);
//        }
//        if(a>0){
//            return "提交成功";
//        }else{
//            return "提交失败";
//        }
//    }
    @RequestMapping("select")
    public List<FOrder> select(){
    return fOrderMapper.selectList(null);
}
    @RequestMapping("insert")
    public Integer insert(FOrder texture){
        return fOrderMapper.insert(texture);
    }
    @RequestMapping("delete")
    public Integer delete(Integer id){
        return fOrderMapper.deleteById(id);
    }
    @RequestMapping("update")
    public Integer update(FOrder texture){

        return fOrderMapper.updateById(texture);
    }

    @RequestMapping("select2")
    public Object select2(){//未发货
        return fOrderDao.select2();
    }
    @RequestMapping("select3")
    public Object select3(){//已发货
        return fOrderDao.select3();
    }
    @RequestMapping("select4")
    public Object select4(){//确认收货
        return fOrderDao.select4();
    }
    @RequestMapping("select5")
    public Object select5(){//退货
        return fOrderDao.select5();
    }
    @RequestMapping("select6")
    public Object select6(){//未发货
        return fOrderDao.select6();
    }
    @RequestMapping("update1")
    public Integer update1(FOrder fOrder, FReturns fReturns){
        Integer state= fOrder.getState();
        Integer f_order=fReturns.getFOrder();
        FOrder fOrder1=new FOrder();
        fOrder1.setId(f_order);
        fOrder1.setState(state);
        return fOrderDao.update1(fOrder1);
    }

}
